package com.jdz.gxq.info.admin.tax.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import com.jdz.gxq.info.admin.tax.bo.Tax;
import com.jdz.gxq.info.admin.tax.form.EditTaxForm;
import com.jdz.gxq.info.admin.tax.service.TaxService;
import com.jdz.gxq.info.common.action.CommonAction;

public class SaveTaxAction extends CommonAction {

	private TaxService taxService = null;

	public ActionForward doExecute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws java.lang.Exception {

		EditTaxForm editTaxForm = (EditTaxForm) form;

		Tax tax = editTaxForm.getTax();

		// tax名重复验证(其他后台逻辑验证也类似处理)
		if (!taxService.checkTaxName(tax, 2)) {
			ActionMessages messages = new ActionMessages();
			messages.add("tax.enterpriseName", new ActionMessage(
					"error.taxNameExisted"));
			addErrors(request, messages);
			return mapping.getInputForward();
		}
		tax.setModifiedBy(getUserId(request));

		taxService.updateTax(tax);

		return mapping.findForward("success");
	}

	public void setTaxService(TaxService taxService) {
		this.taxService = taxService;
	}
}
